package de.gwtprime.client.login;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.Widget;

import de.gwtprime.client.PrimeService;
import de.gwtprime.client.PrimeServiceAsync;
import de.gwtprime.client.widgets.popup.SocialMediaLoginForm;

/**
 * Represents the login-box
 * @author jan
 *
 */
public class LoginContainer extends Composite {

	/**
	 * Create a remote service proxy to talk to the server-side Prime service.
	 */
	private final PrimeServiceAsync primeService = GWT
			.create(PrimeService.class);
	
	interface MyUiBinder extends UiBinder<Widget, LoginContainer> {}
	private static MyUiBinder uiBinder = GWT.create(MyUiBinder.class);

	//@UiField TextBox userNameInput;
	//@UiField PasswordTextBox userPasswordInput;
	//@UiField Button loginButton;
	@UiField Anchor loginButtonGoogle;
	//@UiField Button registerButton;
	@UiField Label authenticationMessage;

	public LoginContainer() {
		// sets listBox
		initWidget(uiBinder.createAndBindUi(this));

	}

//	@UiHandler("loginButton")
//	void handleLoginClick(ClickEvent e) {
//		
//		primeService.login(userNameInput.getValue(), userPasswordInput.getValue(), new AsyncCallback<UserDTO>(){
//
//			@Override
//			public void onFailure(Throwable caught) {
//				// TODO Auto-generated method stub
//				RootPanel.get().add(new Label("not logged in"));
//			}
//
//			@Override
//			public void onSuccess(UserDTO result) {
//				
//				if(result!=null){
//					RootPanel.get().add(new Label("logged in"));
//					AppUtils.EVENT_BUS.fireEvent(new AuthenticationEvent(AuthenticationEventType.LOGIN, result));
//				}
//				else
//					authenticationMessage.setText("Failed to login");
//			}
//			
//		});
//	}
	
	@UiHandler("loginButtonGoogle")
	void handleLoginClickGoogle(ClickEvent e) {
		PopupPanel popup = new PopupPanel();

		popup.add(new SocialMediaLoginForm());
		popup.setGlassEnabled(true);
		popup.setAutoHideEnabled(true);
		popup.setAnimationEnabled(true);
		popup.center();
		popup.show();
		
		
	}
	
//	@UiHandler("registerButton")
//	void handleRegisterButton(ClickEvent e) {
//		
//		DialogBox dialog = new DialogBox();
//		dialog.setText("Register");
//		dialog.setPopupPosition(registerButton.getAbsoluteLeft(), registerButton.getAbsoluteTop()+registerButton.getOffsetHeight());
//		dialog.add(new RegisterContainer(dialog));
//		dialog.show();
//	}
	
}
